<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title> 按歌德巴赫拆分数排序 </title>
</head>
<style>
    body {
        font-family: Consolas, "Courier New", monospace;
        font-size: 24px;
        min-width: 1080px;
        background-color: #333;
        color: #fff;
    }

    main {
        display: flex;
        flex-wrap: wrap;

        div {
            margin: 0.4rem;
            padding: 0.2rem;
            display: flex;
            flex-direction: column;
            background-color: #444;
            text-align: right;

            span:first-child {
                color: #3ff;
            }

            span:last-child {
                color: #ff3;
            }
        }
    }
</style>

<body>
    <header id="HD"></header>
    <main> </main>
</body>
<script src="./primes.js"></script>
<script>
    const MAIN_TAG = document.getElementsByTagName("main")[0];
    const PRIMES_ARRAY = Array.from(PRIMES);
    const orders = [];
    
    const getC = (i) => {
        let j = 1, c = 0, t;
        while (true) {
            t = PRIMES_ARRAY[j];
            if (t >= i) break;
            if (PRIMES.has((i << 1) - t)) c++;
            j++;
        }
        return c;
    }

    const paint = ic => {
        let D = document.createElement("div");
        let c = document.createElement("span");
        let i = document.createElement("span");
        c.textContent = ic.c;
        i.textContent = ic.i;
        D.appendChild(c);
        D.appendChild(i);
        MAIN_TAG.appendChild(D);
    }

    (() => {
        for (let i = 4; i <= 5000; i++) {
            let c = getC(i);
            orders.push({ i, c });
        }

        orders.sort((a, b) => ((a.c - b.c) << 16) + (a.i - b.i));

        for (let i = 0; i < orders.length; i++) {
            paint(orders[i]);
        }
    })();
</script>


</html>